import request from '@/utils/request'
import type { 
  DictType,
  CreateDictType,
  UpdateDictType,
  DictTypeQuery
} from '@/types/api/config/dictType'
import type { 
  DictData,
  CreateDictData,
  UpdateDictData,
  DictDataQuery
} from '@/types/api/config/dictData'
import type { API } from '@/types/api/response'

/* 字典类型相关API */

/**
 * 获取字典类型列表
 * @param params 查询参数
 */
export const getDictTypeList = (params?: DictTypeQuery) =>
  request.get<API.Response<DictType[]>>('/api/config/dict/type/list', { params })

/**
 * 获取字典类型分页列表
 * @param params 查询参数
 */
export const getDictTypePage = (params: DictTypeQuery) =>
  request.get<API.Response<API.PageResult<DictType>>>('/api/config/dict/type/page', { params })

/**
 * 获取字典类型详情
 * @param id 字典类型ID
 */
export const getDictTypeDetail = (id: string) =>
  request.get<API.Response<DictType>>(`/api/config/dict/type/${id}`)

/**
 * 创建字典类型
 * @param data 字典类型信息
 */
export const createDictType = (data: CreateDictType) =>
  request.post<API.Response<DictType>>('/api/config/dict/type', data)

/**
 * 更新字典类型
 * @param id 字典类型ID
 * @param data 字典类型信息
 */
export const updateDictType = (id: string, data: UpdateDictType) =>
  request.put<API.Response<null>>(`/api/config/dict/type/${id}`, data)

/**
 * 删除字典类型
 * @param id 字典类型ID
 */
export const deleteDictType = (id: string) =>
  request.delete<API.Response<null>>(`/api/config/dict/type/${id}`)

/**
 * 批量删除字典类型
 * @param ids 字典类型ID数组
 */
export const batchDeleteDictType = (ids: string[]) =>
  request.delete<API.Response<null>>('/api/config/dict/type', { data: { ids } })

/**
 * 导出字典类型
 * @param params 查询参数
 */
export const exportDictType = (params?: DictTypeQuery) =>
  request.get<BlobPart>('/api/config/dict/type/export', { 
    params, 
    responseType: 'blob'
  })

/**
 * 获取字典数据列表
 * @param params 查询参数
 */
export const getDictDataList = (params: DictDataQuery) =>
  request.get<API.Response<DictData[]>>('/api/config/dict/data/list', { params })

/**
 * 获取字典数据分页列表
 * @param params 查询参数
 */
export const getDictDataPage = (params: DictDataQuery) =>
  request.get<API.Response<API.PageResult<DictData>>>('/api/config/dict/data/page', { params })

/**
 * 获取字典数据详情
 * @param id 字典数据ID
 */
export const getDictDataDetail = (id: string) =>
  request.get<API.Response<DictData>>(`/api/config/dict/data/${id}`)

/**
 * 创建字典数据
 * @param data 字典数据信息
 */
export const createDictData = (data: CreateDictData) =>
  request.post<API.Response<DictData>>('/api/config/dict/data', data)

/**
 * 更新字典数据
 * @param id 字典数据ID
 * @param data 字典数据信息
 */
export const updateDictData = (id: string, data: UpdateDictData) =>
  request.put<API.Response<null>>(`/api/config/dict/data/${id}`, data)

/**
 * 删除字典数据
 * @param id 字典数据ID
 */
export const deleteDictData = (id: string) =>
  request.delete<API.Response<null>>(`/api/config/dict/data/${id}`)

/**
 * 批量删除字典数据
 * @param ids 字典数据ID数组
 */
export const batchDeleteDictData = (ids: string[]) =>
  request.delete<API.Response<null>>('/api/config/dict/data', { data: { ids } })

/**
 * 根据字典类型获取字典数据
 * @param dictType 字典类型
 */
export const getDictDataByType = (dictType: string) =>
  request.get<API.Response<DictData[]>>(`/api/config/dict/data/type/${dictType}`) 